﻿using System;
using FluentExport.CSVExport;
using NUnit.Framework;
using Should.Fluent;

namespace FluentExport.Tests.CSVExportTests
{
    [TestFixture]
    public class CSVExportHelperTests
    {
        [Test]
        public void MustGetPropertyNameCorrectly()
        {
            var csvExportHelper = new CSVExportHelper();

            var propertyName = csvExportHelper.GetPropertyName<DummyClassTest>(d => d.Id);

            propertyName.Should().Not.Be.NullOrEmpty();
            propertyName.Should().Equal("Id");
        }

        [Test]
        public void MustTryGetPropertyNameAndGetIncorrectExpressionException()
        {
            var csvExportHelper = new CSVExportHelper();

            var ex = Assert.Throws<InvalidCastException>(() => csvExportHelper.GetPropertyName<DummyClassTest>(d => d.ToString()));

            ex.Should().Not.Be.Null();
            ex.Message.Should().StartWith("Unable to cast object of type ");
        }

        [Test]
        public void MustGetValueWithoutCommasWithFormatCorrectly()
        {
            var csvExportHelper = new CSVExportHelper();

            var ret = csvExportHelper.FormatValue("Test");

            ret.Should().Not.Be.NullOrEmpty();
            ret.Should().Equal("Test");
        }

        [Test]
        public void MustGetValueWithCommasWithFormatCorrectly()
        {
            var csvExportHelper = new CSVExportHelper();

            var ret = csvExportHelper.FormatValue("Test , Test1");

            ret.Should().Not.Be.NullOrEmpty();
            ret.Should().Equal("\"Test , Test1\"");
        }
    }
}
